package com.rpay.admin.controller.level;

import com.rpay.admin.controller.base.BaseController;
import com.rpay.common.vo.PcsResult;
import com.rpay.model.level.RpayLevel;
import com.rpay.service.level.impl.LevelServiceImpl;
import org.apache.ibatis.session.RowBounds;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 */
@RestController
@RequestMapping(value = "api/level")
public class RpayLevelController extends BaseController {
    @Autowired
    private LevelServiceImpl levelServiceImpl;

    @GetMapping("list")
    public PcsResult getLevelList(@RequestParam(name = "page", defaultValue = "0") Integer page,
                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        RpayLevel rpayLevel = new RpayLevel();
        RowBounds rowBounds = new RowBounds(page > 0 ? page - 1 : 0, pageSize);
        Map result = new HashMap();
        List resultList = levelServiceImpl.getDataList(rpayLevel, rowBounds);
        result.put("list", resultList);
        return PcsResult.build(result);
    }

    @PutMapping
    public PcsResult updateLevel(@RequestBody RpayLevel rpayLevel) throws Exception {
        levelServiceImpl.updateRpayLevel(rpayLevel);
        return newResult();
    }

    /**
     * 根据id 查询rpayLevel 详情
     *
     * @param id
     * @return
     */
    @GetMapping("detail")
    public PcsResult getRpayLevelDetail(Integer id) {
        RpayLevel rpayLevel = levelServiceImpl.getDetail(id);
        return PcsResult.build(rpayLevel);
    }

}
